package com.hdoit.kylin.logical.document.dao.impl;

import java.util.List;

import org.springframework.stereotype.Component;

import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.logical.superbase.model.Employee;
import com.tennetcn.common.utils.FinderExpressionFactory;
import com.hdoit.kylin.logical.document.dao.IReportCataLogEmployeeDao;
import com.hdoit.kylin.logical.document.model.ReportCataLog;
import com.hdoit.kylin.logical.document.model.ReportCataLogEmployee;
import com.hdoit.kylin.logical.viewmodel.document.ReportCataLogEmployeeSearch;
import com.hdoit.kylin.logical.viewmodel.document.ReportCataLogSearch;
/**
 * @author      guoshuren
 * @email       
 * @createtime  2018年02月03日 18:58:54
 * @comment
 */
@Component
public class ReportCataLogEmployeeDaoImpl extends SuperDao<ReportCataLogEmployee> implements IReportCataLogEmployeeDao{

	private List<ReportCataLogEmployee> queryList(ReportCataLogEmployeeSearch search){
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		finderExpression.select("DISTINCT reportCataLogEmployee.*")
						.from(ReportCataLogEmployee.class,"reportCataLogEmployee");
		
		appendFinder(search,finderExpression);
		
		return queryList(finderExpression,search);
	}
	
	private void appendFinder(ReportCataLogEmployeeSearch search,
			IFinderExpression finderExpression) {
		if(search.getReportId() != null){
			finderExpression.andWhere("reportCataLogEmployee.reportCataLogId = #{reportId}")
							.setParam("reportId", search.getReportId());
		}
		if(search.getEmployeeId() != null){
			finderExpression.andWhere("reportCataLogEmployee.employeeId = #{employeeId}")
							.setParam("employeeId", search.getEmployeeId());
		}
		
	}

	@Override
	public List<ReportCataLogEmployee> queryListByEmployee(
			String employeeId) {
		ReportCataLogEmployeeSearch search = new ReportCataLogEmployeeSearch();
		search.setEmployeeId(employeeId);
		return queryList(search);
	}

	@Override
	public List<ReportCataLogEmployee> queryListByReportCataLog(
			String reportId) {
		ReportCataLogEmployeeSearch search = new ReportCataLogEmployeeSearch();
		search.setReportId(reportId);
		return queryList(search);
	}

	@Override
	public int deleteByReportId(String reportId) {
		IFinderExpression finderExpression = FinderExpressionFactory.createExpression();
		finderExpression.delete()
						.from(ReportCataLogEmployee.class)
						.andWhere("reportId = #{reportId}")
						.setParam("reportId", reportId);
		return delete(finderExpression);
	}



}